package java5;

import java.util.Arrays;
import java.util.Scanner;

public class Q5_1Comparable {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		PersonSortable[] arr = new PersonSortable[n];
		for (int i = 0; i < arr.length; i++) {
			String name = in.next();
			int age = in.nextInt();
			arr[i] = new PersonSortable(name, age);
		}
		Arrays.sort(arr);
		for (int i = 0; i < arr.length; i++) {
			System.out.println(arr[i]);
		}
		System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
	}
}

class PersonSortable implements Comparable<PersonSortable> {
	private String name;
	private int age;

	public PersonSortable(String name, int age) {
		this.name = name;
		this.age = age;
	}

	@Override
	public String toString() {
		return name + "-" + age;
	}

	public int compareTo(PersonSortable other) {
		int x = this.getName().compareTo(other.getName());
		if (x != 0)
			return x;
		return this.getAge() - other.getAge();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

}